const Base = require('./base.js');

module.exports = class extends Base {
    indexAction() {
        return this.display();
    };
    async on_stream_not_foundAction(){
        let params = this.post();
        console.log(params);
        let cameraParam = await this.model("camera").where({id: params.stream}).find();
        console.log(cameraParam);
        if(cameraParam != {}){
            const zlParams = {
                secret: 'R1TRHJtO6vDyshWJg88Y1Xx5QkN5eo1u',
                vhost: '192.168.2.22',
                app: params.app,
                stream: params.stream,
                url: cameraParam.url,
                timeout_sec: '30',
            };
            const data = await this.service("http").post("/index/api/addStreamProxy", zlParams);
        }
        
        return this.success();
    }

    async on_stream_none_readerAction(){
        let params = this.post();
        console.log(params);
        //let cameraParam = await this.model("camera").where({id: params.stream}).find();
        //if(cameraParam != {}){
        const zlParams = {
            secret: 'R1TRHJtO6vDyshWJg88Y1Xx5QkN5eo1u',
            app: params.app,
            stream: params.stream,
            schema:params.schema,
        };
            const data = await this.service("http").post("/index/api/close_streams", zlParams);
        //}
        
        return this.success();
    }

};